<?php 
/*
* ----------------------------------------------------------------------------------------------------
* Create Post Type For Testimonial
* @PACKAGE BY TT
* Testimonial
* ----------------------------------------------------------------------------------------------------
*/
add_action('init', 'theme_create_post_type_testimonial');
add_filter("manage_edit-testimonial_columns", "prod_edit_columns_testimonial");
add_action("manage_posts_custom_column",  "prod_custom_columns_testimonial");
/*Create post type for testimonial*/
function theme_create_post_type_testimonial() 
{
	$labels = array(
		'name' => esc_html__( 'Testimonial Items','TT'),
		'singular_name' => esc_html__( 'Testimonial Item','TT' ),
		'add_new' => esc_html__('Add New','TT'),
		'add_new_item' => esc_html__('Add New Testimonial Item','TT'),
		'edit_item' => esc_html__('Edit Testimonial Item','TT'),
		'new_item' => esc_html__('New Testimonial Item','TT'),
		'view_item' => esc_html__('View Testimonial Item','TT'),
		'search_items' => esc_html__('Search Testimonial Item','TT'),
		'not_found' => esc_html__('No Testimonial item found','TT'),
		'not_found_in_trash' => esc_html__('No Testimonial item found in Trash','TT'), 
		'parent_item_colon' => ''
	);

	$args = array(
		'labels' => $labels,
		'public' => false,
		'publicly_queryable' => false,
		'exclude_from_search' => true,
		'show_ui' => true,
		'show_in_menu' => true,
		'capability_type' => 'page',
		'hierarchical' => false,
		'supports' => array('title', 'thumbnail' , 'page-attributes'),
		'has_archive' => false,
		'rewrite' => false,
		'query_var' => false,
		'can_export' => true,
		'show_in_nav_menus' => false,
		'menu_position' => 25,
		'menu_icon' =>   API_URI . '/api_asset/images/icon-slider.png',
	); 

	register_post_type( 'testimonial' , $args );

}


/*Prod edit columns*/
function prod_edit_columns_testimonial($columns)
{
	$newcolumns = array(
		"cb" => "<input type=\"checkbox\" />",
		"Testimonial_avata" => esc_html__('Avata', 'TT'),
		"title" => "Title",
		"Testimonial_content" => esc_html__("Content", 'TT'),
		"Testimonial_project" => esc_html__("Project", 'TT'),
		"Testimonial_company" => esc_html__("Company", 'TT'),
		"Testimonial_email" => esc_html__("Email", 'TT')
	);
	
	$columns= array_merge($newcolumns, $columns);
	
	return $columns;
}


/*Prod custom columns*/
function prod_custom_columns_testimonial($column)
{
	global $post;
	$Testimonial_avata = get_meta_option('Testimonial_avata');
	$title = get_meta_option('title');
	$Testimonial_content = get_meta_option('Testimonial_content');
	$Testimonial_project = get_meta_option('Testimonial_project');
	$Testimonial_company = get_meta_option('Testimonial_company');
	$Testimonial_email = get_meta_option('Testimonial_email');
	
	switch ($column)
	{
		case "Testimonial_avata":
		if($Testimonial_avata)
		{
		echo '<img class="wp-post-image" src="'.$Testimonial_avata.'" width="50" height="50" />';
		}
		break;
		case "title" :
		if($title)
		{
		echo $title;
		}
		break;
		case "Testimonial_content" :
		if($Testimonial_content)
		{
		echo substr($Testimonial_content,0,50);
		}
		break;
		case "Testimonial_project" :
		if($Testimonial_project)
		{
		echo $Testimonial_project;
		}	
		break;
		case "Testimonial_company" :
		if($Testimonial_company)
		{
		echo $Testimonial_company;
		}		
		break;
		case "Testimonial_email" :
		if($Testimonial_email)
		{
		echo $Testimonial_email;
		}		
		break;
	}
}


function theme_Testimonial_context_fixer() {
	if ( get_query_var( 'post_type' ) == 'testimonial' ) {
		global $wp_query;
		$wp_query->is_home = false;
		$wp_query->is_404 = true;
		$wp_query->is_single = false;
		$wp_query->is_singular = false;
	}
}
add_action( 'template_redirect', 'theme_Testimonial_context_fixer' );

?>